#include <string>
#include <iostream>
#include <boost/shared_ptr.hpp>

class Conn
{
    public:
        Conn(){}
        ~Conn(){std::cout << "~conn" << std::endl;}
        void hello()
        { std::cout << "hello" << std::endl;}
};

class MysqlConnPool 
{
public:
    MysqlConnPool()
    {
    }
    ~MysqlConnPool()
    {
    }
    Conn* get_conn()
    { 
        return (new Conn());
    }

};

class Manage
{
    private:
        boost::shared_ptr<Conn> a;
    public:
        Manage(MysqlConnPool m)
        {
            std::cout << a.get() << "use count:" << a.use_count() << std::endl; 
            a.reset(m.get_conn());
            std::cout << a.get() << "use count:" << a.use_count() << std::endl; 
        }
        ~Manage(){}
        void hi()
        {
        
            std::cout << "hi addr:" << a.get() << "use count:" << a.use_count() << std::endl; 
        }
        
};


void test()
{
    /*
    boost::shared_ptr<implementation> sp1(new implementation());
    std::cout<<"The Sample now has "<<sp1.use_count()<<" references\n";

    boost::shared_ptr<implementation> sp2 = sp1;
    std::cout<<"The Sample now has "<<sp2.use_count()<<" references\n";
    
    sp1.reset();
    std::cout<<"After Reset sp1. The Sample now has "<<sp2.use_count()<<" references\n";

    sp2.reset();
    std::cout<<"After Reset sp2.\n";
    */
}

int main()
{
    MysqlConnPool a;
    Conn* b = a.get_conn();
    b->hello();
    //std::cout << c.use_count();
    delete b;
    boost::shared_ptr<Conn> c(a.get_conn());
    (c.get())->hello();
    c->hello();

    Manage m(a);
    m.hi();
}
